// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
    env:'mupp-5gs2863z7cf6873f'
})

// 云函数入口函数
exports.main = async (event, context) => {
	const wxContext = cloud.getWXContext()
	const db=cloud.database()
	const shop=db.collection('shop')
	const shopComments=db.collection('shopComment')
	let openid=wxContext.OPENID

	let skip=event.skip?skip:0
	let res=await shopComments.aggregate()
	.match({
			openid
	})
	.lookup({
	  from:'shop',
	  localField:'shop_id',
	  foreignField:'_id',
	  as:'result'
	})
	.project({
	  time:1,
	  zan:1,
	  content:1,
	  shopId:'$result._id',
	  shopName:'$result.name',
	  shopImg:'$result.img'
	})
	.skip(0)
	.limit(20).end()
	console.log('res',res)
	res=res.list
	return {
		res
	}
}